from django.contrib.auth.hashers import make_password
from rest_framework import serializers
from django.contrib.auth.models import Group

from users.models import User


class AdminSerializer(serializers.ModelSerializer):
    class Meta:
        model=User
        fields="__all__"
        extra_kwargs={
            'password':{
                'write_only': True
            }
        }

    def validate(self, attrs):
        # 密码加密
        # 超级管理员is_staff=True
        attrs['password'] = make_password(attrs['password'])
        attrs['is_staff'] = True

        return attrs
# class GroupSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Group
#         # fields = [
#         #     'id',
#         #     'name',
#         #
#         #     # 当前分组，所拥有对权限
#         #     # 新建分组的时候，前端会传来一个列表: [1,2,3,4]
#         #     'permissions',
#         # ]
#         fields='__all__'